#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>

// http://stackoverflow.com/questions/2031109/understanding-set-getsockopt-so-sndbuf
int main(int argc, char * argv[]) {

	int sockfd, sendbuf;
	socklen_t optlen;

	sockfd = socket(AF_INET, SOCK_STREAM, 0);
	if (sockfd == -1)
		printf("Error");

	int res = 0;
	optlen = sizeof(sendbuf);
	res = getsockopt(sockfd, SOL_SOCKET, SO_SNDBUF, &sendbuf, &optlen);

	if (res == -1)
		printf("Error getsockopt one");
	else
		printf("send buffer size = %d\n", sendbuf);

	sendbuf = 98304;

	printf("sets the send buffer to %d\n", sendbuf);
	res = setsockopt(sockfd, SOL_SOCKET, SO_SNDBUF, &sendbuf, sizeof(sendbuf));

	if (res == -1)
		printf("Error setsockopt");


	// Get buffer size
	optlen = sizeof(sendbuf);
	res = getsockopt(sockfd, SOL_SOCKET, SO_SNDBUF, &sendbuf, &optlen);

	if (res == -1)
		printf("Error getsockopt two");
	else
		printf("send buffer size = %d\n", sendbuf);

	return 0;
}